import 'package:base_pay/entity/purchase/IPurchaseDetails.dart';

//下面这几个包必须要导入才行 in_app_purchase
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:in_app_purchase_android/billing_client_wrappers.dart';
import 'package:in_app_purchase_android/in_app_purchase_android.dart';
import 'package:in_app_purchase_storekit/in_app_purchase_storekit.dart';
import 'package:in_app_purchase_storekit/store_kit_wrappers.dart';
import 'package:mybase/base/tool/empty/FFEmpty.dart';
import 'package:mybase/base/tool/globalMethod/FFSafeValue.dart';
import 'package:mybase/base/tool/pprint/FFLog.dart';

class IOSPurchaseEntity implements IPurchaseDetails {
  PurchaseDetails details;

  IOSPurchaseEntity({
    required this.details,
  });

  @override
  PurchaseDetails getDetail() {
    return details;
  }

  @override
  String? getLocalVerificationData() {
    return details.verificationData.localVerificationData;
  }

  @override
  String? getServerVerificationData() {
    return details.verificationData.serverVerificationData;
  }

  @override
  String? getError() {
    if (details.status == PurchaseStatus.error) {
      AppStorePurchaseDetails appstoreDetail = details as AppStorePurchaseDetails;
      SKError e = appstoreDetail.skPaymentTransaction.error!;
      return "codee${e.code.toString()}";
    }
  }

  @override
  String? getCancel() {
    if (details.status == PurchaseStatus.canceled) {
      AppStorePurchaseDetails appstoreDetail = details as AppStorePurchaseDetails;
      SKError e = appstoreDetail.skPaymentTransaction.error!;
      return "codec${e.code.toString()}";
    }
  }
}
